package com.ciwong.epaper.modules.epaper.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.LinearLayout;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.adapter.ChooseGradeAdapter;
import com.ciwong.epaper.modules.epaper.bean.ChooseGradeBean;
import com.ciwong.epaper.widget.NoScrollListView;

import java.util.List;

/**
 * Created by yyf on 2017/8/17.
 */

public class ChooseGradeDialog extends Dialog {
    private  Context context;
    private List<ChooseGradeBean> chooseGradeBeanList;
    private AdapterView.OnItemClickListener onItemClickListener;

    public ChooseGradeDialog(@NonNull Context context, List<ChooseGradeBean> chooseGradeBeanList, AdapterView.OnItemClickListener onItemClickListener) {
        super(context, R.style.dialog);
        this.context = context;
        this.chooseGradeBeanList = chooseGradeBeanList;
        this.onItemClickListener = onItemClickListener;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }
    public  int getDeviceWidth() {
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        return manager.getDefaultDisplay().getWidth();
    }
    public  int getDeviceHeight() {
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        return manager.getDefaultDisplay().getHeight();
    }
    private void init() {
        View chooseGradeView = LayoutInflater.from(context).inflate(R.layout.dialog_choose_grade, null);
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER;
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(getDeviceWidth(), (int) (getDeviceHeight()*0.65));
        addContentView(chooseGradeView, params);
        NoScrollListView  lv_choose_grade = (NoScrollListView ) findViewById(R.id.lv_choose_grade);
        lv_choose_grade.setAdapter(new ChooseGradeAdapter(chooseGradeBeanList));
        lv_choose_grade.setOnItemClickListener(onItemClickListener);
        findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}
